﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASoft.Led
{
    public class LedPicRCell : LedPicBase
    {
        public LedPicRCell(LedCfg ledCfg, string ledPath) : base(ledCfg, ledPath) { }

        protected override string GetTemplatePicName()
        {
            return "rcell.bmp";
        }

        protected override string GetSendPicName()
        {
            return "rcell1.bmp";
        }

        public override void Create(params object[] ps)
        {
            PrivateCreate(ps[0] as RData, ps[1] as RData, ps[2] as RData);
        }

        void PrivateCreate(RData rData1, RData rData2, RData rData3)
        {
            List<DrawItem> drawItems = new List<DrawItem>();

            ProcessR(typeof(RData), rData1, typeof(RItem), LedCfg.R1, 0, 7, drawItems);
            ProcessR(typeof(RData), rData2, typeof(RItem), LedCfg.R2, 0, 7, drawItems);
            ProcessR(typeof(RData), rData3, typeof(RItem), LedCfg.R3, 0, 7, drawItems);
            CreatePic(drawItems);
        }

        void ProcessR(Type dataType, object rData, Type itemType, object rItem, int startIndex, int endIndex, List<DrawItem> drawItems)
        {
            var tRItem = typeof(RItem);
            for (int i = startIndex; i <= endIndex; i++)
            {
                int x = (int)itemType.GetProperty(String.Format("Cell{0}X", i)).GetValue(rItem, null);
                int y = (int)itemType.GetProperty(String.Format("Cell{0}Y", i)).GetValue(rItem, null);
                string text = (string)dataType.GetProperty(String.Format("Text{0}", i)).GetValue(rData, null);
                drawItems.Add(new DrawItem(text, x, y));
            }
        }
    }
}
